package com.starsea.book.ui.newpage.activity

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.appbar.AppBarLayout
import com.starsea.book.base.VMBaseActivity
import com.starsea.book.databinding.ActivityPersonalPageBinding
import com.starsea.book.databinding.TitleActionEditBinding
import com.starsea.book.ui.newpage.adapter.PersonCommentAdapter
import com.starsea.book.ui.newpage.viewmodel.UserViewModel
import com.starsea.book.ui.newpage.weidget.TitleBarView
import com.starsea.book.utils.viewbindingdelegate.viewBinding
import kotlin.math.abs

/**
 * @author Lee
 * @createTime 2024-08-25 14 GMT+8
 * @desc :
 */
class PersonalPageActivity : VMBaseActivity<ActivityPersonalPageBinding, UserViewModel>() {

    lateinit var mAdapter: PersonCommentAdapter
    override val binding by viewBinding(ActivityPersonalPageBinding::inflate)

    override val viewModel by viewModels<UserViewModel>()
    override fun onActivityCreated(savedInstanceState: Bundle?) {

        binding.titleBarView.setOnLeftTextClickListener {
            finish()
        }

        binding.appBarLayout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
            val offset = abs(verticalOffset * 1.0f) / binding.appBarLayout.totalScrollRange;
            binding.titleBarView.setBackgroundColor(
                Color.argb(
                    (offset * 255).toInt(),
                    255,
                    255,
                    255
                )
            );

        })

        mAdapter = PersonCommentAdapter(this)
        binding.rvContent.layoutManager = LinearLayoutManager(this)
        binding.rvContent.adapter = mAdapter
        mAdapter.add("")
        mAdapter.add("")
        mAdapter.add("")
        mAdapter.add("")
        mAdapter.add("")
        mAdapter.add("")
        mAdapter.add("")
        val titleView = TitleActionEditBinding.inflate(layoutInflater)

        binding.titleBarView.addRightAction(object : TitleBarView.Action<View> {
            override val data: View
                get() = titleView.root

            override
            val onClickListener: View.OnClickListener?
                get() = null
        })

    }


}